package MyApp::Model::Users;

use strict;
use warnings;

use Mojo::Util 'secure_compare';

my %users1;

#密码文件设置绝对路径
open my $COUNT,'<','/home/dahama/文档/count.txt' or die "can't open the file:$!\n";

while (my $line = <$COUNT>) {
	chomp $line;
	my ($user1,$pass1,$role) = split(/ /,$line);

	#$users1{$user1} = $pass1;
	$users1{$user1}->{pass} = $pass1;
	$role =~ s/[\r\n]//g;
	$users1{$user1}->{role} = $role;
}

close $COUNT;

my $USERS = \%users1;

sub new {bless{},shift}


sub check {
	my ($self,$user,$pass) = @_;

	return 1 if $USERS->{$user}->{pass} && secure_compare $USERS->{$user}->{pass}, $pass;

	return undef;
}

#下一步准备扩展角色认证使用“role”


sub checkrole {
	my ($self,$user,$role) = @_;
	return 1 if $USERS->{$user}->{role} && secure_compare $USERS->{$user}->{role}, $role;

	return undef;
}


sub rolevalue {
	my ($self,$user) = @_;

	return $USERS->{$user}->{role};
}

1;